﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Reflection;
namespace App.Utility.Pathing
{
    public static class ControllerPluginPathExtender
    {
        public static ViewResult PluginView(this Controller controller)
        {
            string controllerName = controller.RouteData.GetRequiredString("controller");
            string viewName = controller.RouteData.GetRequiredString("action");
            string assemblyName = controller.GetType().Assembly.FullName.Split(',')[0];
            string pluginPath = String.Format(
                    @"~/Plugin/{0}.dll/{0}.Views.{1}.{2}.aspx",
                    assemblyName,controllerName,viewName
                    );
            return new ViewResult{
                ViewName = pluginPath,
                ViewData = controller.ViewData,
                TempData = controller.TempData
            };
        }
    }
}
